package com.admin.business.electionPropertyRecord;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 业委会委员补选记录
 * @create: 2023-10-28 09:27:23
 **/
@Service("electionPropertyRecordService")
@Slf4j
public class ElectionPropertyRecordService{

    @Resource
    ElectionPropertyRecordDao electionPropertyRecordDao;

    /**
     * 添加业委会委员补选记录,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - user_id_zyw:用户id
     *                   - election_community_name:小区名称
     *                   - election_community_area:小区总专有面积
     *                   - election_community_households:小区约总户数
     *                   - election_community_position:小区位置
     *                   - election_community_economize:省级
     *                   - election_community_market:市级
     *                   - election_community_distinguish:区级
     *                   - election_community_longitude:经度
     *                   - election_community_latitude:纬度
     *                   - election_community_agreement:物业投票平台使用协议：0否，1是
     *                   - election_community_prove:上传图片
     *                   - election_information_identity:身份状态：0业主，1业委会委员
     *                   - industry_committee_filings:上传备案单
     *                   - industry_committee_number:业委会委员总人数
     *                   - user_owner_id:发起人业主id
     *                   - user_owner_director:业委会主任id
     *                   - industry_committee_resolution:是否下载业委会决议：0否，1是
     *                   - industry_committee_no:业委会是否同意：0否，1是
     *                   - filings_unit:备案单位
     *                   - filings_user_name:备案接收人
     *                   - filings_time:备案接收时间
     *                   - filings_img:备案单签收证明(存图片路径）
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return addElectionPropertyRecord(CDO cdoRequest) {
        electionPropertyRecordDao.addElectionPropertyRecord(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新业委会委员补选记录数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - user_id_zyw:用户id
     *                   - election_community_name:小区名称
     *                   - election_community_area:小区总专有面积
     *                   - election_community_households:小区约总户数
     *                   - election_community_position:小区位置
     *                   - election_community_economize:省级
     *                   - election_community_market:市级
     *                   - election_community_distinguish:区级
     *                   - election_community_longitude:经度
     *                   - election_community_latitude:纬度
     *                   - election_community_agreement:物业投票平台使用协议：0否，1是
     *                   - election_community_prove:上传图片
     *                   - election_information_identity:身份状态：0业主，1业委会委员
     *                   - industry_committee_filings:上传备案单
     *                   - industry_committee_number:业委会委员总人数
     *                   - user_owner_id:发起人业主id
     *                   - user_owner_director:业委会主任id
     *                   - industry_committee_resolution:是否下载业委会决议：0否，1是
     *                   - industry_committee_no:业委会是否同意：0否，1是
     *                   - filings_unit:备案单位
     *                   - filings_user_name:备案接收人
     *                   - filings_time:备案接收时间
     *                   - filings_img:备案单签收证明(存图片路径）
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return updateElectionPropertyRecordById(CDO cdoRequest) {
        electionPropertyRecordDao.updateElectionPropertyRecordById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除业委会委员补选记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return deleteElectionPropertyRecordById(CDO cdoRequest){
        int count = electionPropertyRecordDao.deleteElectionPropertyRecordById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除业委会委员补选记录数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return deleteElectionPropertyRecord(CDO cdoRequest) {
        int count = electionPropertyRecordDao.deleteElectionPropertyRecord(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取业委会委员补选记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getElectionPropertyRecordById(CDO cdoRequest) {
        CDO cdoMapperResult = electionPropertyRecordDao.getElectionPropertyRecordById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取业委会委员补选记录数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getElectionPropertyRecordListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = electionPropertyRecordDao.getElectionPropertyRecordListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = electionPropertyRecordDao.getElectionPropertyRecordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取业委会委员补选记录数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getElectionPropertyRecordListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = electionPropertyRecordDao.getElectionPropertyRecordListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = electionPropertyRecordDao.getElectionPropertyRecordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
